package com.kuson.springcloud.service.ipml;

import cn.hutool.core.lang.UUID;
import com.kuson.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;

@EnableBinding(Source.class) //提供一个生产消息的实现类。注入到spring容器中
public class IMessageProviderImpl implements IMessageProvider {
    @Resource
    private MessageChannel output;
    /**
     * 实现发送个消息队列的数据
     * @return
     */
    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("*****serial: "+serial);

        return serial;
    }
}
